Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lookup fallback to t! #68

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

varphone
Copy link
Contributor

Add lookup fallback to t!

Example of a Lookup Fallback Pattern

Range to match: zh-Hant-CN-x-private1-private2

  1. zh-Hant-CN-x-private1-private2
  2. zh-Hant-CN-x-private1
  3. zh-Hant-CN
  4. zh-Hant
  5. zh
  6. (default)

Closed: #67

let mut current_locale = locale;
while let Some(fallback_locale) = _rust_i18n_lookup_fallback(current_locale) {
if let Some(value) = _RUST_I18N_BACKEND.translate(fallback_locale, key) {
return value.to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有可能避免 to_string 没?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,这个仅是 fallback 的时候才会触发,还好。你试试看 to_string 能否避免,如果可以那就减少一次创建 String,不行的话也可以的。

Copy link
Contributor Author

@varphone varphone Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不行,translate() 返回的是 Option<&str>,而 _rust_i18n_translate() 返回的是 String

@huacnlee huacnlee merged commit cb93545 into longbridge:main Jan 15, 2024
2 checks passed
@varphone varphone deleted the feature/lookup-fallback branch January 20, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants